package com.example.demo.controller;

import com.example.demo.model.Girl;
import com.example.demo.model.StatusEnum;
import com.example.demo.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Lx on 2018/6/26.
 */
@RestController
public class TestController {

    @Autowired
    private GirlRepository girlRepository;
    @GetMapping("hello/springBoot")
    public String helloSpringBoot(){

        return "helloSpringBoot";
    }
    @RequestMapping(value = "/hello/test/{id}",method = RequestMethod.GET)
    public String hello(@PathVariable("id") String id){
        return id;
    }

    @RequestMapping(value = "/hello/test")
    public Girl postTest(@RequestBody Girl girl){
        girl.setAge(12);
        girl.setName("小芳");
        girl.setId(2);
        return girl;
    }

    @GetMapping("girl/findGirl")
    public List<Girl> findGirl(){
        return girlRepository.findAll();
//        List<Girl>girlList =  girlRepository.findByName("aaa");
//        return null;
    }

    @PostMapping("girl/addGirl")
    public String addGirl(@RequestBody Girl girl) throws Exception{
         girlRepository.save(girl);
         return "success";
    }

    @PostMapping("girl/updateGirl")
    public String updateGirl(@RequestBody Girl girl) throws Exception{
         girlRepository.save(girl);
         return "success";
    }

    @GetMapping("girl/deleteGirl")
    public String deleteGirl(@RequestParam("id") Integer id) throws Exception{
         girlRepository.delete(id);
         return "success";
    }

    @GetMapping("girl/queryTest")
    public Integer queryTest(){
        System.out.println(StatusEnum.QUANBU);
        System.out.println(StatusEnum.QUANBU.getStatus());
        return StatusEnum.QUANBU.getStatus();
    }


}
